package com.ruoyi.irtu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.irtu.domain.IrtuFirmware;
import com.ruoyi.irtu.service.IIrtuFirmwareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 固件Controller
 * 
 * @author wb
 * @date 2023-03-05
 */
@RestController
@RequestMapping("/irtu/firmware")
public class IrtuFirmwareController extends BaseController
{
    @Autowired
    private IIrtuFirmwareService irtuFirmwareService;

    /**
     * 查询固件列表
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:list')")
    @GetMapping("/list")
    public TableDataInfo list(IrtuFirmware irtuFirmware)
    {
        startPage();
        List<IrtuFirmware> list = irtuFirmwareService.selectIrtuFirmwareList(irtuFirmware);
        return getDataTable(list);
    }

    /**
     * 导出固件列表
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:export')")
    @Log(title = "固件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IrtuFirmware irtuFirmware)
    {
        List<IrtuFirmware> list = irtuFirmwareService.selectIrtuFirmwareList(irtuFirmware);
        ExcelUtil<IrtuFirmware> util = new ExcelUtil<IrtuFirmware>(IrtuFirmware.class);
        util.exportExcel(response, list, "固件数据");
    }

    /**
     * 获取固件详细信息
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:query')")
    @GetMapping(value = "/{firmwareId}")
    public AjaxResult getInfo(@PathVariable("firmwareId") Long firmwareId)
    {
        return success(irtuFirmwareService.selectIrtuFirmwareByFirmwareId(firmwareId));
    }

    /**
     * 新增固件
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:add')")
    @Log(title = "固件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IrtuFirmware irtuFirmware)
    {
        return toAjax(irtuFirmwareService.insertIrtuFirmware(irtuFirmware));
    }

    /**
     * 修改固件
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:edit')")
    @Log(title = "固件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IrtuFirmware irtuFirmware)
    {
        return toAjax(irtuFirmwareService.updateIrtuFirmware(irtuFirmware));
    }

    /**
     * 删除固件
     */
    @PreAuthorize("@ss.hasPermi('irtu:firmware:remove')")
    @Log(title = "固件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{firmwareIds}")
    public AjaxResult remove(@PathVariable Long[] firmwareIds)
    {
        return toAjax(irtuFirmwareService.deleteIrtuFirmwareByFirmwareIds(firmwareIds));
    }
}
